package com.purchase.ml.resource.dashboard;

import com.purchase.ml.bean.base.ApiRestResult;
import com.purchase.ml.bean.req.order.OrderAddReq;
import com.purchase.ml.bean.req.order.OrderInvoiceQueryReq;
import com.purchase.ml.bean.req.order.OrderQueryReq;
import com.purchase.ml.bean.req.shoppingcart.ProductCartReq;
import com.purchase.ml.bean.res.dashboard.DashboardAdminRes;
import com.purchase.ml.bean.res.dashboard.DashboardAgentRes;
import com.purchase.ml.bean.res.dashboard.DashboardDealerRes;
import com.purchase.ml.bean.res.dashboard.DashboardMasterDealerRes;
import com.purchase.ml.bean.res.shoppingcart.ShoppingCartRes;
import com.purchase.ml.consts.PermissionsConst;
import com.purchase.ml.entity.prod.SysProductSku;
import com.purchase.ml.enums.RetStatusNum;
import com.purchase.ml.resource.BaseResource;
import com.purchase.ml.service.dashboard.DashboardService;
import com.purchase.ml.service.order.SysOrderService;
import com.purchase.ml.service.shoppingcart.SysShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author kyyang
 * Created 2021-03-04
 */

@RestController
@RequestMapping("/dashboard")
@Api(tags = "仪表盘")
@Slf4j
public class DashboardResource extends BaseResource {

    @Autowired
    private DashboardService dashboardService;

    @Autowired
    private SysOrderService sysOrderService;

    @RequestMapping(method = RequestMethod.POST, path = "/admin")
    @ApiOperation("管理员查询仪表盘")
    @RequiresPermissions(value = {PermissionsConst.DASHBOARD_ADMIN_QUERY})
    public ApiRestResult adminDashboard() {
        DashboardAdminRes result =  dashboardService.queryAdminDashboard();
        return ApiRestResult.ok(result);
    }

    @RequestMapping(method = RequestMethod.POST, path = "/agent")
    @ApiOperation("大代理查询仪表盘")
    @RequiresPermissions(value = {PermissionsConst.DASHBOARD_AGENT_QUERY})
    public ApiRestResult agentDashboard() {
        DashboardAgentRes result =  dashboardService.queryAgentDashboard();
        return ApiRestResult.ok(result);
    }

    @RequestMapping(method = RequestMethod.POST, path = "/masterdealer")
    @ApiOperation("主经销商查询仪表盘")
    @RequiresPermissions(value = {PermissionsConst.DASHBOARD_MASTERDEALER_QUERY})
    public ApiRestResult masterDealerDashboard() {
        DashboardMasterDealerRes result =  dashboardService.queryMasterDealerDashboard();
        return ApiRestResult.ok(result);
    }

    @RequestMapping(method = RequestMethod.POST, path = "/dealer")
    @ApiOperation("经销商仪表盘")
    @RequiresPermissions(value = {PermissionsConst.DASHBOARD_DEALER_QUERY})
    public ApiRestResult dealerDashboard() {
        DashboardDealerRes result =  dashboardService.queryDealerDashboard();
        return ApiRestResult.ok(result);
    }

    @RequestMapping(method = RequestMethod.POST, path = "/recent/order")
    @ApiOperation("最近订单查询:查询售卖者为自己的订单")
    @RequiresPermissions(PermissionsConst.ORDER_QUERY)
    public ApiRestResult recentOrderQuery() {
        return ApiRestResult.ok(sysOrderService.orderRecentQuery());
    }
}